package com.zh.common.utils

import com.zh.common.utils.toast.ZToastUtils.showShort
import android.text.InputFilter
import android.text.Spanned
import android.text.TextUtils
import com.zh.common.utils.toast.ZToastUtils
import java.util.regex.Pattern

internal class InputNameFilterNoSpace : InputFilter {
    var prompt: String? = null

    constructor() {}
    constructor(prompt: String?) {
        this.prompt = prompt
    }

    var pattern = Pattern.compile("[^a-zA-Z_.()\\s\\u4E00-\\u9FA5]") //[^a-zA-Z.()（）\u4E00-\u9FA5]

    override fun filter(
        source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int
    ): CharSequence? {
        val matcher = pattern.matcher(source)
        return if (!matcher.find()) {
            null
        } else {
            if (!TextUtils.isEmpty(prompt)) {
                //TODO:提示
                showShort(prompt, false)
            }
            ""
        }
    }
}